package cn.quang.search.toolkit.component;

import cn.quang.search.toolkit.enums.DataSourceTypeEnum;
import cn.quang.search.toolkit.enums.SearchOperator;

/**
 * 查询条件项的基类
 * @author: 杨联泉
 * @since: 2018/04/16 15:20
 */
public abstract class AbstractSearchItem implements ISearch {

    private ISearch parentGroup;

    protected DataSourceTypeEnum dsType;
    protected String col;
    protected SearchOperator operator;

    public AbstractSearchItem(DataSourceTypeEnum dsType, String col, SearchOperator operator) {
        this.dsType = dsType;
        this.col = col;
        this.operator = operator;
    }

    public AbstractSearchItem() { }

    /**
     * 当前是否叶子节点
     * searchItem一定是叶子节点
     */
    @Override
    public boolean isLeaf() {
        return true;
    }

    public void setParentGroup(ISearch parentGroup) {
        this.parentGroup = parentGroup;

        if(SearchSecurtityUtil.existsCirculateParent(this)){
            this.parentGroup = null;
            throw new IllegalArgumentException("设置AbstractSearchItem的parentGroup后，查询条件链存在死锁！");
        }
    }

    public ISearch getParentGroup() {
        return parentGroup;
    }
}
